<%@page import="warehouse.StaffBean"%>
<%@page import="java.sql.*"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>

<jsp:useBean id="databaseBean" scope="session" class="warehouse.DatabaseBean"/>  

    
<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title>职工信息更新表单</title>
	
	<link rel="stylesheet" href="layui/css/layui.css">
	<script src="layui/layui.js"></script>
	<script>
	layui.use('form', function(){
	  var form = layui.form;
	});
	
	</script>


</head>
<body>
<%
	//接收参数，如果接收到了就是修改，如果没有就是新增
	String staffNoString = request.getParameter("staffNo");
	int staffNo = 0;
	StaffBean staff = new StaffBean();
	
	if(staffNoString!=null){
		//修改参数指定的信息
		//获取对应的信息，并作为默认值填入
		
		try{
			staffNo = Integer.valueOf(staffNoString);
		}catch(Exception e){
			staffNo=0;
		}
		staff = StaffBean.queryStaff(staffNo);
		if(staff==null){
			staff = new StaffBean();
		}
	}

%>
	<h1 style="text-align:center">职工信息更新表单</h1>
	<form class="layui-form" action="staff_update.jsp" method="post">
		<!-- 职工号。为0意味着进行添加，为特定数值意味着修改-->
		<input type="hidden" name="staffNo" value="<%=staffNo%>"/>
		<!-- 姓名 -->
		<div class="layui-form-item">
		    <label class="layui-form-label">姓名</label>
		    <div class="layui-input-block">
		      <input type="text" name="name" value="<%=staff.getName() %>" required  lay-verify="required" placeholder="请输入职工姓名" autocomplete="off" class="layui-input">
		    </div>
	  	</div>
	  	<!-- 性别 -->
	  	<div class="layui-form-item">
		    <label class="layui-form-label">性别</label>
		    <div class="layui-input-block">
		      <input type="radio" name="gender" value="true" title="男" <%=staff.isGender()?"checked":"" %>>
		      <input type="radio" name="gender" value="false" title="女" <%=staff.isGender()?"":"checked" %>>
		    </div>
	  	</div>
	    <!-- 年龄 -->
	    <div class="layui-form-item">
		    <label class="layui-form-label">年龄</label>
		    <div class="layui-input-block">
		      <input type="text" name="age" value="<%=staff.getAge()==0?"":staff.getAge() %>" required  lay-verify="required|number" placeholder="请输入职工年龄" autocomplete="off" class="layui-input">
		    </div>
	  	</div>
	    
	    <!-- 电话号码 -->
	    <div class="layui-form-item">
		    <label class="layui-form-label">电话号码</label>
		    <div class="layui-input-block">
		      <input type="text" name="telenumber" value="<%=staff.getTelenumber() %>" required  lay-verify="required|phone" placeholder="请输入电话号码" autocomplete="off" class="layui-input">
		    </div>
	  	</div>
	    
	    <!-- 所属仓库 -->
	    <div class="layui-form-item">
		    <label class="layui-form-label">所属仓库</label>
		    <div class="layui-input-block">
		      <select name="warehouseNo" lay-verify="required"> 
		        <option value="">请选择仓库编号</option>
		        <%
				String sql=String.format("SELECT warehouseNo,address FROM warehouse;");
				ResultSet rs=databaseBean.executeQuery(sql);
				while(rs.next()){
					%>
					<option value="<%=rs.getInt("warehouseNo")%>" <%=staff.getWarehouseNo()== rs.getInt("warehouseNo")?"selected":""%>>
						<%=rs.getInt("warehouseNo")+" "+rs.getString("address")%>
					</option>	
					<%
				}
				rs.close();
				%>
		        
		      </select>
		    </div> 
  		</div>
	    
	    <div class="layui-form-item" id="submitDiv">
	    <div class="layui-input-block">
	      	<button class="layui-btn" lay-submit lay-filter="*">立即提交</button>
	      	<button type="reset" class="layui-btn layui-btn-primary">重置</button>
	    </div>
  		</div>
	</form>


</body>
</html>